package com.sduept.nwld.dataserver.controller.riskalarm;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.faces.view.ViewScoped;
import javax.inject.Named;

import org.springframework.beans.factory.annotation.Autowired;

import com.sduept.bigdata.document.entity.core.RecordAttachment;
import com.sduept.bigdata.document.services.RecordAttachmentManager;
import com.sduept.bigdata.fault.protection.model.ProtectInterruptAlarm;
import com.sduept.bigdata.fault.protection.service.ProtectDeviceAlarmQueryManager;
import com.sduept.bigdata.web.jsf.controller.AbstractController;
import com.sduept.core.dao.SuperDAO;
import com.sduept.message.entity.AlarmMessageCheck;
import com.sduept.message.manager.AlarmMessageCheckManager;

@Named
@ViewScoped
public class ProtectChannelException extends AbstractController{
     
	@Autowired
	private ProtectDeviceAlarmQueryManager pc;
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
    private List<ProtectInterruptAlarm> protectChannelList=null;
    private AlarmMessageCheck check=null;
    
    private List<RecordAttachment> attachments = new ArrayList<>();
	
    @Autowired
    private SuperDAO dao;
    @Autowired
    private AlarmMessageCheckManager amc;
    @Autowired
	private RecordAttachmentManager ram;
    
    @PostConstruct
	private void init() {
    	String oId=getParameter("oId");
    	String msgId=getParameter("msgId");
    	ProtectInterruptAlarm alarm=dao.findById(oId, ProtectInterruptAlarm.class);
    	check=amc.getAlarmMessageCheckByMsgId(msgId);
    	if(alarm!=null){
    		Date start = alarm.getEventStart();
    		Date end = new Date(alarm.getEventStart().getTime()+86400000);
    		protectChannelList=pc.getProtectInterruptAlarmByProtectIdAndDate(alarm.getProtectId(), start, end);
    	}
    	if(null==check) {
			check=new AlarmMessageCheck();
		}
    	attachments = ram.getAttachmentsByOId(check.getId());
    }
    
	public List<ProtectInterruptAlarm> getProtectChannelList() {
		return protectChannelList;
	}
	public void setProtectChannelList(List<ProtectInterruptAlarm> protectChannelList) {
		this.protectChannelList = protectChannelList;
	}
	public AlarmMessageCheck getCheck() {
		return check;
	}
	public void setCheck(AlarmMessageCheck check) {
		this.check = check;
	}

	public List<RecordAttachment> getAttachments() {
		return attachments;
	}

	public void setAttachments(List<RecordAttachment> attachments) {
		this.attachments = attachments;
	}
	
}
